home *** CD-ROM | disk | FTP | other *** search
/ Video Toaster 4.3 / Video Toaster v4.3.iso / 4.2 / arexx / editor / oz / 2-xfade < prev    next >
Text File  |  1998-04-16  |  7KB  |  251 lines

  1. /* X-Fade v.1.3 performs an audio crossfade with 2 VIDEO clips (& can matches a SLOW FADE effect's speed.)  */
  2.  
  3. /* By Aussie - ©1995 Michael Holten
  4.  
  5.    To use - select & highlight a SLOW FADE (video dissolve) icon that is inbetween two VIDEO clips. < OR > select the second of two adjoining VIDEO clips.  Then run this ARexx routine.  You can control audio fade time & the volume of the second clip.  The audio tracks will overlap and fade at the same speed. */
  6.  
  7.  
  8. call remlib('PROJECT_REXX_PORT')
  9. call addlib('PROJECT_REXX_PORT',0)
  10.  
  11.  
  12. start_loc=croutonspot()
  13. project_end=CroutonsinProject()
  14. f_fadetime=60
  15.  
  16.  
  17. /* --------------- see if we're on an ALGO effect & get length of fade */
  18.  
  19. call croutonpick(start_loc)
  20. FadeOK=0
  21. If croutontype()~="CLIP" then FadeOK=1
  22.  
  23. if croutontype()="ALGO" then do
  24.    test=croutonname()
  25.    test1=right(test,length(test)-lastpos("/",test))
  26.    test2=("SMOOTH FADE" = upper(test1))
  27.    if test2~=0 then do
  28.       f_numfields=croutongettag(numfields)
  29.       f_fadetime=f_numfields%2
  30.       end
  31.    end
  32.  
  33. /* --- test that the 2 (surrounding) clips are VIDEO clips */
  34. videois=0
  35. if start_loc>0 then do
  36.    current_spot=start_loc-1
  37.    call croutonpick(current_spot)
  38.    if croutontype()="CLIP" then do
  39.       AudOnP=croutongettag(AUDIOON) /* is there audio on */
  40.       if AudOnP>6 then do
  41.          videois=1
  42.          vol1P=croutongettag(AUDIOVOLUME1)
  43.          vol2P=croutongettag(AUDIOVOLUME2)
  44.          end
  45.       end
  46.    end
  47.  
  48. if start_loc<project_end then do
  49.    current_spot=start_loc+FadeOK
  50.    call croutonpick(current_spot)
  51.    if croutontype()="CLIP" then do
  52.       AudOnN=croutongettag(AUDIOON) /* is there audio on */
  53.       if AudOnN>6 then do
  54.          videois=(videois+1)
  55.          vol1N=croutongettag(AUDIOVOLUME1)
  56.          vol2N=croutongettag(AUDIOVOLUME2)
  57.          end
  58.       end
  59.    end
  60.  
  61. call croutonpick(start_loc)
  62.  
  63. /* --- wait for any screen update delay --- */
  64. call time('R')
  65. do while (time('E')<0.5)
  66.     end
  67.  
  68. call req_open("<< Crossfade - by Aussie >>","--------------------------------","  Select SECOND of 2 adjoining VIDEO clips, or the EFFECT between 2 video clips,  ","  then run this routine.  It will crossfade audios at same speed.  ")
  69.  
  70. /* --- weed out errors */
  71.  
  72.  
  73. if (AudOnP<7) | (AudOnN<7) then do
  74.    call req_tell("<< Canceled >>"," A VIDEO clip has audio turned OFF!")
  75.    call quit2()
  76.    end
  77.  
  78. if videois~=2 then do
  79.    test=req_tell("Sorry... canceled"," Selected 2nd of 2 VIDEO clips,","or the EFFECT between 2 VIDEO clips.")
  80.    call quit2()
  81.    end
  82.  
  83. /* --- Calculate Volumes --- */
  84. highvol=0
  85. vol1=((vol1N/655.35)+0.5)%1
  86. if vol1<0 then vol1=0
  87. if vol1>100 then vol1=100
  88. vol2=((vol2N/655.35)+0.5)%1
  89. if vol2<0 then vol2=0
  90. if vol2>100 then vol2=100
  91. if vol1>highvol then highvol=vol1
  92. if vol2>highvol then highvol=vol2
  93.  
  94.  
  95. /*  ------------- get previous audio levels */
  96. highvolprev=0
  97. vol1prev=((vol1P/655.35)+0.5)%1
  98. if vol1prev<0 then vol1prev=0
  99. if vol1prev>100 then vol1prev=100
  100. vol2prev=((vol2P/655.35)+0.5)%1
  101. if vol2prev<0 then vol2prev=0
  102. if vol2prev>100 then vol2prev=100
  103. if vol1prev>highvolprev then highvolprev=vol1prev
  104. if vol2prev>highvolprev then highvolprev=vol2prev
  105.  
  106.  
  107. /* ------------ get volumes & fade speed */
  108.  
  109. do until fadetime<=(25*60)
  110.   f_want=req_time("Fade Time (max 25:00):",f_fadetime)
  111.   if f_want= "CANCEL" then call quit2()
  112.  
  113.   fm=substr(f_want,4,2)
  114.   fs=substr(f_want,7,2)
  115.   ff=substr(f_want,10,2)
  116.   f_all=((fm*1800)+(fs*30)+ff)*2
  117.   fadetime=f_all
  118.   end
  119.  
  120. f_want2=right(f_want,5)
  121. f_numfields = fadetime
  122.  
  123. volume=req_number("1st clip vol:" highvolprev "   2nd volume:" highvol ,highvol,0,100)
  124. if volume="CANCEL" then call quit2()
  125.  
  126. /* --------------------------- Proceed or not */
  127.  
  128. test=req_tell("Dissolve to volume" volume "in " f_want2 ,"      Perform this audio dissolve?")
  129. if test=0 then call quit2()
  130. call req_close()
  131.  
  132. call checkprev()
  133. call checknext()
  134.  
  135. call croutonpick(start_loc)
  136. call req_error("OZ:  All Done   <<< Crossfade created >>>")
  137. call remlib("PROJECT_REXX_PORT")
  138. exit
  139.  
  140.  
  141.  
  142. CheckPrev:
  143. /* go to previous clip & if CLIP then adjust audio out & audio fade */
  144. current_spot=start_loc-1
  145. call croutonpick(current_spot)
  146. if croutontype()="CLIP" then do
  147.    p_recfields=croutongettag(recfields)
  148.    p_clipstartfield=croutongettag(clipstartfield)
  149.    p_duration=croutongettag(duration)
  150.    p_audiostart=croutongettag(audiostart)
  151.    p_audioattack=croutongettag(audioattack)
  152.    pv_end=p_clipstartfield+p_duration
  153.    pf=f_numfields
  154.  
  155. /* Is audio IN after Video OUT (weird but possible) */
  156.    if p_audiostart< pv_end then do
  157.  
  158. /* calc split audio fade into 2 frame increments */
  159.       t1=pf%4
  160.       if (pf//4)~=0 then t1=pf%4+1
  161.       t3=t1%2
  162.       if (t1//2)~=0 then t3=t1%2+1
  163.       ta=(t1-t3)*4
  164.       tb=t3*4
  165.       paw_end=pv_end+tb
  166.  
  167. /* is there enough video at end for audio fade? */
  168.       if paw_end>p_recfields then do
  169.          paw_end=p_recfields
  170.          tb=paw_end-pv_end
  171.          pf=ta+tb
  172.          end
  173.       paw_duration=paw_end-p_audiostart
  174.       call croutonsettag(audioduration,paw_duration)
  175.  
  176. /* is audio attack or delayed audio IN going to overlap? */
  177.       if (p_audioattack+pf)>paw_duration then do
  178.          ta=paw_duration-p_audioattack-tb
  179.          pf=ta+tb
  180.          end
  181.  
  182.       call croutonsettag(audiodecay,pf)
  183.       call croutonsettag(panelmode,1)
  184.       end
  185.    end
  186. return
  187.  
  188.  
  189. Checknext:
  190. /* go to next clip & if CLIP then adjust audio in point and fade in */
  191. current_spot=start_loc+FadeOK
  192. call croutonpick(current_spot)
  193. if croutontype()="CLIP" then do
  194.    n_clipstartfield=croutongettag(clipstartfield)
  195.    n_duration=croutongettag(duration)
  196.    nv_end=n_clipstartfield+n_duration
  197.    n_audioduration=croutongettag(audioduration)
  198.    n_audiostart=croutongettag(audiostart)   
  199.    naw_end=n_audiostart+n_audioduration
  200.  
  201. /*  Is audio OUT before Video IN (weird but possible) */
  202.    if naw_end>n_clipstartfield then do
  203.       nf=f_numfields
  204.  
  205. /* calc split audio fade */
  206.       t1=nf%4
  207.       if (nf//4)~=0 then t1=nf%4+1
  208.       t3=t1%2
  209.       if (t1//2)~=0 then t3=t1%2+1
  210.       tb=(t1-t3)*4
  211.       ta=t3*4
  212.  
  213.  /* is there enough video at top for audio fade? */
  214.       if ta>n_clipstartfield then do
  215.          ta=n_clipstartfield
  216.          nf=ta+tb
  217.          end
  218.       n_audiostart=n_clipstartfield-ta
  219.       n_audioduration=naw_end-n_audiostart
  220.  
  221. /* Is audio decay or audio OUT going to overlap? */
  222.       n_audiodecay=croutongettag(audiodecay)
  223.       if (n_audiodecay+nf+n_audiostart)>naw_end then do
  224.          tb=naw_end-n_audiodecay-n_audiostart-ta
  225.          nf=ta+tb
  226.          end
  227.       call croutonsettag(audiostart,n_audiostart)
  228.       call croutonsettag(audioduration,n_audioduration)
  229.       call croutonsettag(audioattack,nf)
  230.       call croutonsettag(panelmode,1)
  231.  
  232.       if volume~= highvol then do
  233.          vol1=volume
  234.          vol1=vol1*655.35
  235.          call croutonsettag(AUDIOVOLUME1,vol1)
  236.          vol2=volume
  237.          vol2=vol2*655.35
  238.          call croutonsettag(AUDIOVOLUME2,vol2)
  239.          end
  240.       end
  241.    end
  242. return
  243.  
  244.  
  245. quit2:
  246. call req_close()
  247. call req_error("OZ:  <<< Last Operation Canceled >>>")
  248. call remlib("PROJECT_REXX_PORT")
  249.  
  250. exit
  251.